package com.lisn.coordinatorlib;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;


import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;


public class PartClassifyFragment extends Fragment {
    private static final String TAG = PartClassifyFragment.class.getSimpleName();

    RecyclerView rvPartClassify;
    private ArrayList<String> datas = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_part_classify, container, false);
        rvPartClassify = view.findViewById(R.id.rv_part_classify);
        init();
        return view;
    }

    private void init() {
        for (int i = 0; i < 55; i++) {
            datas.add("");
            ImageView imageView = new ImageView(getActivity());
            Bitmap bitmap = BitmapFactory.decodeFile("");
            imageView.setImageBitmap(bitmap);
        }
        rvPartClassify.setLayoutManager(new GridLayoutManager(getActivity(), 2));

        MyRecyclerViewAdapter adapter = new MyRecyclerViewAdapter(rvPartClassify);
        adapter.setData(datas);
        rvPartClassify.setAdapter(adapter);

        adapter.setOnItemClickListener(new MyRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                Log.e(TAG, "onItemClick:position= " + position + " view=" + view.getId());
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                Log.e(TAG, "onItemLongClick:position= " + position + " view=" + view.getId());
                return true;
            }
        });

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
}
